<template>
    <div class="organization-list">
        <!-- <h2 class="title">{{ $route.meta.title }}</h2> -->

      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item prop="institutionName">
          <el-input
            v-model="queryParams.institutionName"
            placeholder="请输入医院名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <div class="table">
        <el-table v-loading="loading" @selection-change="handleSelectionChange"
                  :data="tableData"
                  border
                  fit
                  style="width: 100%"
                  header-cell-class-name="table-header-cell"
                  :class="tableData.length === 0 ? 'table-empty' : ''"
        >
          <el-table-column
            label="序号"
            type="index"
            width="80">
          </el-table-column>
          <el-table-column label="医院名称" align="center" prop="name" />
          <el-table-column label="辖区" align="center" prop="areaname" />
          <el-table-column label="诊疗科目数" align="center" prop="medicalSpecialtiesValue" />
          <el-table-column label="监控数" align="center" prop="monitorValue" />
          <el-table-column label="白名单开关" align="center" prop="enabled" >
            <template slot-scope="scope">
              <el-tag v-if="scope.row.enabled === '0'">关</el-tag>
              <el-tag v-else >开</el-tag>
            </template>

          </el-table-column>>
          <el-table-column label="">
            <template slot-scope="scope">
              <div class="edit-region" @click="editRegion(scope.row)">修改辖区</div>
            </template>
          </el-table-column>
          <el-table-column label="详情" width="300" align="center">
            <template slot-scope="scope">
              <div class="operation">
                <div style="margin-left: 40%;" @click="handleView(scope.row)">查看</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
        <el-dialog
            v-if="editDialogVisible"
            title="修改辖区"
            :visible.sync="editDialogVisible"
            width="30%"
            :before-close="handleClose"
            class="edit-dialog"
            top="40vh"
        >
          <el-form ref="form" :model="form" :rules="rules" label-width="100px">
            <div class="edit-box">
              <div class="row1">
                <el-select v-model="form.provinceCode" filterable  placeholder="请选择省" @change="getCity">
                  <el-option
                    v-for="item in provinceOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code">
                  </el-option>
                </el-select>
                <el-select v-model="form.cityCode" filterable placeholder="请选择市" @change="getArea">
                  <el-option
                    v-for="item in cityOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code">
                  </el-option>
                </el-select>
                <el-select v-model="form.medicalAreaname" filterable placeholder="请选择区/县">
                  <el-option
                    v-for="item in districtOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.name">
                  </el-option>
                </el-select>
              </div>

              <div class="submit" @click="submitForm">修改辖区</div>
            </div>
          </el-form>

        </el-dialog>

        <!-- 查看医院详情弹窗 -->
        <el-dialog v-if="hospitalDetailVisible" title="医院详情" :visible.sync="hospitalDetailVisible" width="1200px"
          :before-close="handleHospitalDetailClose" top="40vh">
            <div class="organization-detail" style="
              height: 100%;
              display: flex;
              flex-direction: column;
              cursor: default;
            ">
              <div class="title" style="
                margin-top: 10px;
                font-weight: bold;
                font-size: 26px;
                line-height: 26px;
                color: #4B4B4B;
              ">医疗机构详情</div>
              <div class="card" style="
                background-color: #fff;
                padding: 19px 13px 19px;
                margin-top: 14px;
              ">
                <div class="org-name" style="
                  font-weight: bold;
                  font-size: 20px;
                  color: #4B4B4B;
                  line-height: 39px;
                ">{{ dataInfo.orgName }}</div>
                <div class="org-address" style="
                  font-weight: 500;
                  font-size: 16px;
                  color: #4B4B4B;
                  line-height: 30px;
                ">地址：{{ dataInfo.orgAddress }}</div>
                <div class="legal-person" style="
                  font-weight: 500;
                  font-size: 16px;
                  color: #4B4B4B;
                  line-height: 30px;
                ">法人：{{ dataInfo.legalPerson }}</div>
              </div>
              <div class="card" style="
                background-color: #fff;
                padding: 19px 13px 19px;
                margin-top: 14px;
              ">
                <SubTitle title="基本信息"></SubTitle>
                <div class="row" style="
                  font-weight: 500;
                  font-size: 16px;
                  color: #4B4B4B;
                  line-height: 25px;
                  margin-top: 6px;
                ">医院名称：{{ dataInfo.orgName }}</div>
                <div class="row" style="
                  font-weight: 500;
                  font-size: 16px;
                  color: #4B4B4B;
                  line-height: 25px;
                  margin-top: 6px;
                ">医院简介：</div>
                <div class="row" style="
                  font-weight: 500;
                  font-size: 16px;
                  color: #4B4B4B;
                  line-height: 25px;
                  margin-top: 6px;
                ">{{ dataInfo.description }}</div>
                <div class="org-detail-info" style="
                  display: flex;
                  flex-wrap: wrap;
                ">
                  <div class="info-item" v-for="item in dataInfo.detailInfo" :key="item.label" style="
                    width: 530px;
                    display: flex;
                    align-items: center;
                    margin-top: 8px;
                    font-weight: 500;
                    font-size: 16px;
                    color: #8B8B8B;
                  ">
                    <div class="label" style="
                      white-space: nowrap;
                      width: 133px;
                    ">{{ item.label }}：</div>
                    <div class="value">{{ item.value }}</div>
                  </div>
                </div>
              </div>
              <div class="card" style="
                background-color: #fff;
                padding: 19px 13px 19px;
                margin-top: 14px;
              ">
                <div class="title" style="
                  margin-top: 10px;
                  font-weight: bold;
                  font-size: 26px;
                  line-height: 26px;
                  color: #4B4B4B;
                ">诊疗科目</div>
                <div class="medical-subject" v-for="item in dataInfo.medicalSubject" :key="item" style="
                  margin-top: 24px;
                  border-radius: 5px;
                  border: 1px solid #DCDCDC;
                  text-align: center;
                  height: 39px;
                  line-height: 39px;
                  font-weight: 500;
                  font-size: 16px;
                  color: #505050;
                  padding: 0 30px;
                  display: inline-block;
                  margin-right: 13px;
                ">{{ item }}</div>
              </div>
              <div class="card" style="
                background-color: #fff;
                padding: 19px 13px 19px;
                margin-top: 14px;
              ">
                <SubTitle title="技术资质"></SubTitle>
                <div class="tech-qualification-container" style="
                  display: flex;
                  flex-wrap: wrap;
                  margin-top: 20px;
                ">
                  <div class="item" v-for="item in dataInfo.qualification" :key="item.label" style="
                    font-weight: 500;
                    font-size: 16px;
                    color: #8B8B8B;
                    margin-right: 120px;
                  ">{{ item.label }}：{{ item.value }}</div>
                </div>
              </div>
              <div class="card" style="
                background-color: #fff;
                padding: 19px 13px 19px;
                margin-top: 14px;
              ">
                <div class="title" style="
                  margin-top: 10px;
                  font-weight: bold;
                  font-size: 26px;
                  line-height: 26px;
                  color: #4B4B4B;
                ">医师列表</div>
                <div class="table" style="
                  flex: 1;
                  background-color: #fff;
                  margin: 13px 0 16px;
                ">
                  <el-table
                    :data="dockorList"
                    border
                    fit
                    style="width: 100%"
                    header-cell-class-name="table-header-cell"
                  >
                    <el-table-column
                      label="序号"
                      type="index"
                      width="100px"
                    ></el-table-column>
                    <el-table-column label="医生姓名" align="center" prop="name" />
                    <el-table-column label="医师类别" align="center" prop="parcticeclass" />
                    <el-table-column label="任职资格" align="center" prop="workcpet" />
                    <el-table-column label="执业范围" align="center" prop="parcticescope" />
                    <el-table-column label="主要执业机构" align="center" prop="unit" />
                    <el-table-column label="美容专业" align="center" prop="beautyMajor" />
                    <el-table-column label="技术资质" align="center" prop="technicalQualification" />
                    <el-table-column label="精麻处方权" align="center" prop="anesthetist" />
                    <el-table-column label="操作">
                      <template slot-scope="scope">
                        <div class="operation">
                          <div>查看</div>
                        </div>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </div>

        </el-dialog>
    </div>
</template>
<script>
  import { listNation, getNation, delNation, addNation, updateNation, exportNation } from "@/api/system/nation";
  import { listProvince, listCity, listArea, listStreet, listVillage} from "@/api/his/province";
  import { listDockor} from "@/api/his/dockor";
export default {
  name: 'OrganizationList',
  data() {
    return {
      dataInfo: {
          orgName: '',
          orgAddress: '',
          legalPerson: '',
          description: '',
          medicalSubject: [],
          qualification: [

          ],
          detailInfo: [

          ],
      },
      tableData: [

      ],

      warningTableConfig: [
          {
              field: 'order',
              title: '序号',
          },
          {
              field: 'rule',
              title: '预警规则',
          },
          {
              field: 'content',
              title: '预警内容',
          },
      ],
      warningTableData: [
          {
              order: 1,
              rule: '抗菌药物处方权规则',
              content: '“吴俊“的抗菌药物处方权为“无抗菌药物权限”'
          },
          {
              order: 2,
              rule: '药品/项目名称药物规则',
              content: '(4+7国基)头孢呋辛酯片”为非限制使用级抗菌药物'
          }
      ],
      dockorList: [],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 国家机构表格数据
      nationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        registerNumber: null,
        institutionName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        registerNumber: [
          {required: true, message: "登记号不能为空", trigger: "blur"}
        ],
        institutionName: [
          {required: true, message: "机构名称不能为空", trigger: "blur"}
        ],
      },
      personTotal: 25689,
      keyword: '',
      editDialogVisible: false,
      editData: null,
      hospitalDetailVisible: false,

      tableData: [
        {
          order: '01',
          name: '毛石镇卫生院',
          region: '毛石镇',
          subjectCount: 30,
          monitorCount: 40,
          whiteListSwitch: '开',
        },
        {
          order: '02',
          name: '毛石镇卫生院',
          region: '毛石镇',
          subjectCount: 30,
          monitorCount: 40,
          whiteListSwitch: '开',
        },
      ],
      provinceOptions: [],
      cityOptions: [],
      districtOptions: [],
    }
  },
  created() {
    this.getList();
    this.listProvince()
    /*this.listCity()
    this.listArea()*/
  },
  methods: {
    myGetList(row) {
      getNation(row).then(response => {
        console.log(response)
        this.dataInfo.orgName = response.data.institutionName;
        this.dataInfo.orgAddress = response.data.medicalAddress;
        this.dataInfo.legalPerson = response.data.medicalLegalrepresentative;
        this.dataInfo.description = '';
        for (let i = 0; i < response.data.medicalSpecialtiesName.split("/").length; i++) {
          this.dataInfo.medicalSubject.push(response.data.medicalSpecialtiesName.split("/")[i])
        }
        this.dataInfo.detailInfo = [
          {
            label: '统一社会信用代码',
            value: response.data.medicalUscc
          },
          {
            label: '所有制形式',
            value: response.data.medicalOwnership
          },
          {
            label: '是否有放射所有权',
            value: ''
          },
          {
            label: '登记号',
            value: response.data.registerNumber
          },
          {
            label: '机构属性',
            value: response.data.medicalCategory
          },
          {
            label: '放射诊疗许可证',
            value: ''
          },
          {
            label: '全国唯一识别码',
            value: response.data.uniqueCode
          }
        ],
        this.getDockorList(response.data.institutionName)
      });
    },
    /** 查询国家机构列表 */
    listProvince() {
      listProvince().then(response => {
        this.provinceOptions = response;
      });
    },
    getCity() {
      listCity(this.form).then(response => {
        this.cityOptions = response;
      });
    },
    getArea() {
      listArea(this.form).then(response => {
        this.districtOptions = response;
      });
    },
    getList() {
      this.loading = true;
      listNation(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uniqueCode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.uniqueCode)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加国家机构";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const registerNumber = row.number
      console.log(registerNumber)
      getNation(registerNumber).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改国家机构";
        this.getDockorList(response.data.registerNumber)
      });
    },
    getDockorList(registerNumber) {
      this.loading = true;
      this.queryParams.registerNumber = registerNumber
      listDockor(this.queryParams).then(response => {
        this.dockorList = response.rows;
        
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateNation(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.editDialogVisible = false
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const uniqueCodes = row.uniqueCode || this.ids;
      this.$modal.confirm('是否确认删除国家机构编号为"' + uniqueCodes + '"的数据项？').then(function () {
        return delNation(uniqueCodes);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有国家机构数据项？').then(() => {
        this.exportLoading = true;
        return exportNation(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    },
    editRegion(scope) {
      this.form.registerNumber = scope.number
      this.form.medicalAreaname = ''
      this.form.provinceCode = ''
      this.form.cityCode = ''
      this.editDialogVisible = true
    },
    handleClose() {
      this.form = {}
      this.editDialogVisible = false
      this.editData = null
    },
    handleView(row) {
      // this.$router.push({ name: 'organizationDetail', params: { number: scope.number}});
      this.getDockorList(row.number);
      this.myGetList(row.number);
      this.hospitalDetailVisible = true;
    }
  }
}
</script>
<style scoped lang="scss">
.organization-list {
    height: 100%;
    display: flex;
    flex-direction: column;
    margin-left: 40px;
    margin-top: 30px;
}

.bread-crumb {
    margin-top: 21px;
    padding-left: 20px;
}

.title {
    font-size: 26px;
    color: #4B4B4B;
    font-weight: bold;
    margin: 18px 0 24px;
}

.detail {
    margin-top: 23px;
    margin-left: 20px;
    padding: 12px 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: 5px;

    .search-input {
        width: 264px;
        height: 47px;
        background: #FFFFFF;
        border-radius: 5px;

        ::v-deep input {
            line-height: 45px;
            height: 47px;
            display: inline-block;
        }

        ::v-deep .el-input__icon {
            line-height: 45px;
            height: 45px;
            vertical-align: -0.15em;
            color: #4373F1;
        }
    }

    .table {
        flex: 1;
        background-color: #fff;
        margin: 13px 0 16px;

        ::v-deep .table-header-cell {
            background-color: #EBEFF8;
            padding-left: 21px;
            font-weight: 500;
            font-size: 16px;
            color: #414141;
        }
        .el-table {
            height: 100%;
        }
        ::v-deep .el-table__cell {
            padding-left: 21px;
            font-weight: 500;
            font-size: 16px;
            color: #414141;
        }
        :v-deep .el-table__body-wrapper {
            height: 100%;
        }
        :v-deep .el-table__empty-block {
            height: 100%;
        }
        .operation {
            display: flex;
            align-items: center;
            height: 100%;

            .view, .edit, .delete {
                cursor: pointer;
                font-weight: 500;
                font-size: 16px;
                color: #4373F1;
                height: 16px;
                line-height: 16px;
                background-repeat: no-repeat;
                background-position: 0 center;
                user-select: none;
            }
        }
    }
}

.edit-box {
    display: flex;
    flex-direction: column;
    align-items: center;

    ::v-deep .el-dialog__footer {
        display: none;
    }

    .row1 {
        display: flex;

        .el-select {
            margin-right: 7px;

            &:nth-last-child(1) {
                margin-right: 0;
            }
        }
    }

    .row2 {
        width: 100%;
        margin-top: 7px;

        .el-select {
            width: 100%;
        }
    }

    .submit {
        width: 164px;
        height: 56px;
        background: #4373F1;
        border-radius: 5px;
        user-select: none;
        line-height: 56px;
        color: #fff;
        text-align: center;
        margin-top: 22px;
        cursor: pointer;
    }
}
.edit-region {
    font-weight: 500;
    font-size: 16px;
    color: #4373F1;
    cursor: pointer;
}
::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 40vh !important;
}
.organization-detail {
    height: 100%;
    display: flex;
    flex-direction: column;
    cursor: default;

    .title {
        margin-top: 10px;
        font-weight: bold;
        font-size: 26px;
        line-height: 26px;
        color: #4B4B4B;
    }

    .org-name {
        font-weight: bold;
        font-size: 20px;
        color: #4B4B4B;
        line-height: 39px;
    }

    .org-address, .legal-person {
        font-weight: 500;
        font-size: 16px;
        color: #4B4B4B;
        line-height: 30px;
    }

    .row {
        font-weight: 500;
        font-size: 16px;
        color: #4B4B4B;
        line-height: 25px;
        margin-top: 6px;
    }

    .org-detail-info {
        display: flex;
        flex-wrap: wrap;

        .info-item {
            width: 530px;
            display: flex;
            align-items: center;
            margin-top: 8px;
            font-weight: 500;
            font-size: 16px;
            color: #8B8B8B;

            .label{
                white-space: nowrap;
                width: 133px;
            }
        }
    }
  .medical-subject {
        margin-top: 24px;
        border-radius: 5px;
        border: 1px solid #DCDCDC;
        text-align: center;
        height: 39px;
        line-height: 39px;
        font-weight: 500;
        font-size: 16px;
        color: #505050;
        padding: 0 30px;
        display: inline-block;
        margin-right: 13px;
    }

    .tech-qualification-container {
        display: flex;
        flex-wrap: wrap;
        margin-top: 20px;

        .item {
            font-weight: 500;
            font-size: 16px;
            color: #8B8B8B;
            margin-right: 120px;
        }

    }
}
.card {
    background-color: #fff;
    padding: 19px 13px 19px;
    margin-top: 14px;
}
.flex-1 {
    flex: 1;
}
.table {
    flex: 1;
    background-color: #fff;
    margin: 13px 0 16px;

    ::v-deep .table-header-cell {
        background-color: #EBEFF8;
        padding-left: 21px;
        font-weight: 500;
        font-size: 16px;
        color: #414141;
    }
    .el-table {
        height: 100%;
    }
    ::v-deep .el-table__cell {
        padding-left: 21px;
        font-weight: 500;
        font-size: 16px;
        color: #414141;
    }
    :v-deep .el-table__body-wrapper {
        height: 100%;
    }
    :v-deep .el-table__empty-block {
        height: 100%;
    }

}
.operation {
    display: flex;
    align-items: center;
    height: 100%;

    .view {
        cursor: pointer;
        font-weight: 500;
        font-size: 16px;
        color: #4373F1;
        height: 16px;
        line-height: 16px;
        background-repeat: no-repeat;
        background-position: 0 center;
        user-select: none;
        padding-left: 20px;
    }
    .view {
            background-image: url('~@/assets/images/table/view.png');
    }
}
</style>
